package cn.stylefeng.guns.modular.rms.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.rms.entity.CompanyWelfare;
import cn.stylefeng.guns.modular.rms.mapper.CompanyWelfareMapper;
import cn.stylefeng.guns.modular.rms.model.params.CompanyWelfareParam;
import cn.stylefeng.guns.modular.rms.model.result.CompanyWelfareResult;
import  cn.stylefeng.guns.modular.rms.service.CompanyWelfareService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 公司福利表 服务实现类
 * </p>
 *
 * @author yzb
 * @since 2021-03-23
 */
@Service
public class CompanyWelfareServiceImpl extends ServiceImpl<CompanyWelfareMapper, CompanyWelfare> implements CompanyWelfareService {

    @Override
    public void add(CompanyWelfareParam param){
        CompanyWelfare entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(CompanyWelfareParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(CompanyWelfareParam param){
        CompanyWelfare oldEntity = getOldEntity(param);
        CompanyWelfare newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public CompanyWelfareResult findBySpec(CompanyWelfareParam param){
        return null;
    }

    @Override
    public List<CompanyWelfareResult> findListBySpec(CompanyWelfareParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(CompanyWelfareParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(CompanyWelfareParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private CompanyWelfare getOldEntity(CompanyWelfareParam param) {
        return this.getById(getKey(param));
    }

    private CompanyWelfare getEntity(CompanyWelfareParam param) {
        CompanyWelfare entity = new CompanyWelfare();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
